/**
 * 获取两个坐标点之间的距离
 * @param lat1
 * @param lng1
 * @param lat2
 * @param lng2
 */
export function getDistance(lat1: number, lng1: number, lat2: number, lng2: number) {
  // 如果上面的值不存在
  if (!lat1 || !lng1 || !lat2 || !lng2)
    return false

  const radLat1 = (lat1 * Math.PI) / 180.0
  const radLat2 = (lat2 * Math.PI) / 180.0
  const a = radLat1 - radLat2
  const b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0
  let s = 2 * Math.asin(
    Math.sqrt(
      Math.sin(a / 2) ** 2
      + Math.cos(radLat1) * Math.cos(radLat2) * Math.sin(b / 2) ** 2,
    ),
  )
  s = s * 6378.137
  s = Math.round(s * 10000) / 10000
  // return s
  // 结尾保留两位小数
  return s.toFixed(2)
}

export function mapIncludePoints(mapCtx: any, markers: any) {
  mapCtx.includePoints({
    points: markers,
    padding: [80, 40, 20, 40],
    success(res) {
      console.log('move 成功: ', res)
    },
    fail(err) {
      console.log('move 失败: ', err)
    },
    complete(res) {
      console.log('move 完成', res)
    },
  })
}
